import yaml
import os
from utils.logutil import logger

# 读取yaml文件
def read_data_yaml():
  yaml_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), './config/data.yaml')
  with open(yaml_path, "r", encoding="utf-8") as f:
    data = yaml.load(f, Loader=yaml.FullLoader)
    return data


def read_shebei_yaml():
  yaml_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), './config/shebei.yaml')
  with open(yaml_path, "r", encoding="utf-8") as f:
    data = yaml.load(f, Loader=yaml.FullLoader)
    return data

# 改变channelCode编码
def change_channelCode():
    yaml_data = read_data_yaml()
    yaml_data['channelCode'] == 1
    return yaml_data


# code码判断
def judge_code(code):
    if code == 200:
        return 1
    elif code == 400:
        assert 0, logger.error('code为400 失败')
    elif code == 401:
        assert 0, logger.error('code为401 需要验证')
    elif code == 404:
        assert 0, logger.error('code为404 无此服务')
    elif code == 1001:
        assert 0, logger.error('code为1001错误，设备不支持该功能，或者掉线')
    elif code == 1002:
        assert 0, logger.error('code为1002错误')



